package fairygui.editor.gui
{
   import fairygui.GRoot;
   import fairygui.Margin;
   import fairygui.event.GTouchEvent;
   import flash.events.Event;
   
   public class EGList extends EGComponent
   {
      
      public static const SINGLE_COLUMN:String = "column";
      
      public static const SINGLE_ROW:String = "row";
      
      public static const FLOW_HZ:String = "flow_hz";
      
      public static const FLOW_VT:String = "flow_vt";
      
      public static const PAGINATION:String = "pagination";
       
      
      private var _layout:String;
      
      private var _selectionMode:String;
      
      private var _lineGap:int;
      
      private var _columnGap:int;
      
      private var _items:Array;
      
      private var _defaultItem:String;
      
      private var _clipSharpness:Margin;
      
      private var _autoResizeItem1:Boolean;
      
      private var _autoResizeItem2:Boolean;
      
      private var _repeatX:int;
      
      private var _repeatY:int;
      
      private var _align:String;
      
      private var _verticalAlign:String;
      
      private var _lastSelectedIndex:int;
      
      private var _selectionController:EController;
      
      private var _selectionControllerFlag:Boolean;
      
      public function EGList()
      {
         super();
         this._items = [];
         this._layout = SINGLE_COLUMN;
         this._selectionMode = "single";
         this._autoResizeItem1 = true;
         this._autoResizeItem2 = false;
         this._align = "left";
         this._verticalAlign = "top";
         this._lastSelectedIndex = -1;
         this.objectType = ObjectTypes.LIST;
      }
      
      public function get layout() : String
      {
         return this._layout;
      }
      
      public function set layout(param1:String) : void
      {
         if(this._layout != param1)
         {
            this._layout = param1;
            this.buildItems();
         }
      }
      
      public function get selectionMode() : String
      {
         return this._selectionMode;
      }
      
      public function set selectionMode(param1:String) : void
      {
         this._selectionMode = param1;
      }
      
      public function get lineGap() : int
      {
         return this._lineGap;
      }
      
      public function set lineGap(param1:int) : void
      {
         if(this._lineGap != param1)
         {
            this._lineGap = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get columnGap() : int
      {
         return this._columnGap;
      }
      
      public function set columnGap(param1:int) : void
      {
         if(this._columnGap != param1)
         {
            this._columnGap = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get repeatX() : int
      {
         return this._repeatX;
      }
      
      public function set repeatX(param1:int) : void
      {
         if(this._repeatX != param1)
         {
            this._repeatX = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get repeatY() : int
      {
         return this._repeatY;
      }
      
      public function set repeatY(param1:int) : void
      {
         if(this._repeatY != param1)
         {
            this._repeatY = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get defaultItem() : String
      {
         return this._defaultItem;
      }
      
      public function set defaultItem(param1:String) : void
      {
         var _loc2_:String = null;
         var _loc3_:Boolean = false;
         var _loc4_:Object = null;
         if(param1)
         {
            _loc2_ = this._defaultItem;
            this._defaultItem = param1;
            _loc3_ = false;
            for each(_loc4_ in this._items)
            {
               if(_loc4_[0] == _loc2_)
               {
                  _loc4_[0] = param1;
                  _loc3_ = true;
               }
            }
            if(_loc3_)
            {
               this.buildItems();
            }
         }
         else
         {
            this._defaultItem = param1;
         }
      }
      
      public function get autoResizeItem() : Boolean
      {
         if(this._layout == SINGLE_COLUMN || this._layout == SINGLE_ROW)
         {
            return this._autoResizeItem1;
         }
         return this._autoResizeItem2;
      }
      
      public function set autoResizeItem(param1:Boolean) : void
      {
         if(this._layout == SINGLE_COLUMN || this._layout == SINGLE_ROW)
         {
            if(this._autoResizeItem1 != param1)
            {
               this._autoResizeItem1 = param1;
               setBoundsChangedFlag();
            }
         }
         else if(this._autoResizeItem2 != param1)
         {
            this._autoResizeItem2 = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get autoResizeItem1() : Boolean
      {
         return this._autoResizeItem1;
      }
      
      public function set autoResizeItem1(param1:Boolean) : void
      {
         if(this._autoResizeItem1 != param1)
         {
            this._autoResizeItem1 = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get autoResizeItem2() : Boolean
      {
         return this._autoResizeItem2;
      }
      
      public function set autoResizeItem2(param1:Boolean) : void
      {
         if(this._autoResizeItem2 != param1)
         {
            this._autoResizeItem2 = param1;
            setBoundsChangedFlag();
         }
      }
      
      public function get items() : Array
      {
         return this._items;
      }
      
      public function set items(param1:Array) : void
      {
         this._items = param1;
         this.buildItems();
      }
      
      public function get align() : String
      {
         return this._align;
      }
      
      public function set align(param1:String) : void
      {
         if(this._align != param1)
         {
            this._align = param1;
            this.setBoundsChangedFlag();
         }
      }
      
      public function get verticalAlign() : String
      {
         return this._verticalAlign;
      }
      
      public function set verticalAlign(param1:String) : void
      {
         if(this._verticalAlign != param1)
         {
            this._verticalAlign = param1;
            this.setBoundsChangedFlag();
         }
      }
      
      public function get selectionController() : String
      {
         if(this._selectionController && this._selectionController.parent)
         {
            return this._selectionController.name;
         }
         return null;
      }
      
      public function set selectionController(param1:String) : void
      {
         var _loc2_:EController = null;
         if(param1)
         {
            _loc2_ = parent.getController(param1);
         }
         this._selectionController = _loc2_;
      }
      
      public function get selectionControllerObj() : EController
      {
         return this._selectionController;
      }
      
      public function setSelection(param1:int) : void
      {
         if(this._selectionMode == "none")
         {
            return;
         }
         this.clearSelection();
         if(param1 < 0 || param1 >= numChildren)
         {
            return;
         }
         var _loc2_:EGObject = getChildAt(param1);
         if(_loc2_ is EGComponent && EGComponent(_loc2_).extention is EGButton)
         {
            EGButton(EGComponent(_loc2_).extention).selected = true;
         }
      }
      
      public function clearSelection() : void
      {
         var _loc3_:EGObject = null;
         var _loc1_:int = this.numChildren;
         var _loc2_:int = 0;
         while(_loc2_ < _loc1_)
         {
            _loc3_ = getChildAt(_loc2_);
            if(_loc3_ is EGComponent && EGComponent(_loc3_).extention is EGButton)
            {
               EGButton(EGComponent(_loc3_).extention).selected = false;
            }
            _loc2_++;
         }
      }
      
      public function addItem(param1:String) : EGObject
      {
         return this.addItemAt(param1,numChildren);
      }
      
      public function addItemAt(param1:String, param2:int) : EGObject
      {
         var _loc5_:EGButton = null;
         var _loc3_:EPackageItem = pkg.project.getItemByURL(param1);
         if(_loc3_ == null)
         {
            return null;
         }
         var _loc4_:EGObject = EUIObjectFactory.createObject(_loc3_,editMode == 1?1:0);
         if(_loc4_ is EGComponent)
         {
            _loc5_ = EGComponent(_loc4_).extention as EGButton;
            if(_loc5_ != null)
            {
               _loc5_.changeStageOnClick = false;
            }
            _loc4_.addEventListener(GTouchEvent.CLICK,this.__clickItem);
         }
         return addChildAt(_loc4_,param2);
      }
      
      private function __clickItem(param1:Event) : void
      {
         var _loc2_:EGObject = EGObject(param1.currentTarget);
         this.setSelectionOnEvent(_loc2_);
         if(scrollPane != null)
         {
            scrollPane.scrollToView(_loc2_,true);
         }
         this.dispatchEvent(new EItemEvent(EItemEvent.CLICK,_loc2_));
      }
      
      private function setSelectionOnEvent(param1:EGObject) : void
      {
         var _loc5_:GRoot = null;
         var _loc6_:int = 0;
         var _loc7_:int = 0;
         var _loc8_:int = 0;
         var _loc9_:EGComponent = null;
         var _loc10_:EGButton = null;
         if(!(param1 is EGComponent) || !(EGComponent(param1).extention is EGButton) || this._selectionMode == "none")
         {
            return;
         }
         var _loc2_:Boolean = false;
         var _loc3_:EGButton = EGComponent(param1).extention as EGButton;
         var _loc4_:int = getChildIndex(param1);
         if(this._selectionMode == "single")
         {
            if(!_loc3_.selected)
            {
               this.clearSelectionExcept(param1);
               _loc3_.selected = true;
            }
         }
         else
         {
            _loc5_ = pkg.project.editorWindow.groot;
            if(_loc5_.shiftKeyDown)
            {
               if(!_loc3_.selected)
               {
                  if(this._lastSelectedIndex != -1)
                  {
                     _loc6_ = Math.min(this._lastSelectedIndex,_loc4_);
                     _loc7_ = Math.max(this._lastSelectedIndex,_loc4_);
                     _loc7_ = Math.min(_loc7_,numChildren - 1);
                     _loc8_ = _loc6_;
                     while(_loc8_ <= _loc7_)
                     {
                        _loc9_ = getChildAt(_loc8_) as EGComponent;
                        if(_loc9_ != null)
                        {
                           _loc10_ = _loc9_.extention as EGButton;
                           if(_loc10_ != null && !_loc10_.selected)
                           {
                              _loc10_.selected = true;
                           }
                        }
                        _loc8_++;
                     }
                     _loc2_ = true;
                  }
                  else
                  {
                     _loc3_.selected = true;
                  }
               }
            }
            else if(_loc5_.ctrlKeyDown || this._selectionMode == "multipleSingleClick")
            {
               _loc3_.selected = !_loc3_.selected;
            }
            else if(!_loc3_.selected)
            {
               this.clearSelectionExcept(param1);
               _loc3_.selected = true;
            }
            else
            {
               this.clearSelectionExcept(param1);
            }
         }
         if(!_loc2_)
         {
            this._lastSelectedIndex = _loc4_;
         }
         if(_loc3_.selected)
         {
            this.updateSelectionController(_loc4_);
         }
      }
      
      private function clearSelectionExcept(param1:EGObject) : void
      {
         var _loc4_:EGComponent = null;
         var _loc5_:EGButton = null;
         var _loc2_:int = numChildren;
         var _loc3_:int = 0;
         while(_loc3_ < _loc2_)
         {
            _loc4_ = getChildAt(_loc3_) as EGComponent;
            if(_loc4_ != null)
            {
               _loc5_ = _loc4_.extention as EGButton;
               if(_loc5_ != null && _loc4_ != param1 && _loc5_.selected)
               {
                  _loc5_.selected = false;
               }
            }
            _loc3_++;
         }
      }
      
      public function resizeToFit(param1:int = 2147483647, param2:int = 0) : void
      {
         var _loc4_:int = 0;
         var _loc5_:EGObject = null;
         var _loc6_:int = 0;
         ensureBoundsCorrect();
         var _loc3_:int = this.numChildren;
         if(param1 > _loc3_)
         {
            param1 = _loc3_;
         }
         if(param1 == 0)
         {
            if(this._layout == SINGLE_COLUMN || this._layout == FLOW_HZ)
            {
               this.viewHeight = param2;
            }
            else
            {
               this.viewWidth = param2;
            }
         }
         else
         {
            _loc4_ = param1 - 1;
            _loc5_ = null;
            while(_loc4_ >= 0)
            {
               _loc5_ = this.getChildAt(_loc4_);
               if(_loc5_.visible)
               {
                  break;
               }
               _loc4_--;
            }
            if(_loc4_ < 0)
            {
               if(this._layout == SINGLE_COLUMN || this._layout == FLOW_HZ)
               {
                  this.viewHeight = param2;
               }
               else
               {
                  this.viewWidth = param2;
               }
            }
            else if(this._layout == SINGLE_COLUMN || this._layout == FLOW_HZ)
            {
               _loc6_ = _loc5_.y + _loc5_.height;
               if(_loc6_ < param2)
               {
                  _loc6_ = param2;
               }
               this.viewHeight = _loc6_;
            }
            else
            {
               _loc6_ = _loc5_.x + _loc5_.width;
               if(_loc6_ < param2)
               {
                  _loc6_ = param2;
               }
               this.viewWidth = _loc6_;
            }
         }
      }
      
      override protected function handleSizeChanged() : void
      {
         super.handleSizeChanged();
         setBoundsChangedFlag();
      }
      
      override public function handleControllerChanged(param1:EController) : void
      {
         super.handleControllerChanged(param1);
         if(this._selectionController == param1 && !this._selectionControllerFlag)
         {
            this._selectionControllerFlag = true;
            this.setSelection(this._selectionController.selectedIndex);
            this._selectionControllerFlag = false;
         }
      }
      
      private function updateSelectionController(param1:int) : void
      {
         if(this._selectionController && !this._selectionControllerFlag && param1 < this._selectionController.pageCount)
         {
            this._selectionControllerFlag = true;
            this._selectionController.selectedIndex = param1;
            this._selectionControllerFlag = false;
         }
      }
      
      private function buildItems() : void
      {
         var _loc3_:Array = null;
         var _loc4_:EGObject = null;
         var _loc1_:int = this._items.length;
         this.removeChildren();
         var _loc2_:int = 0;
         while(_loc2_ < _loc1_)
         {
            _loc3_ = this._items[_loc2_];
            _loc4_ = this.addItem(_loc3_[0]);
            if(_loc4_ is EGComponent && EGComponent(_loc4_).extention)
            {
               if(EGComponent(_loc4_).extention is EGButton)
               {
                  if(_loc3_[1])
                  {
                     EGButton(EGComponent(_loc4_).extention).title = _loc3_[1];
                  }
                  if(_loc3_[2])
                  {
                     EGButton(EGComponent(_loc4_).extention).icon = _loc3_[2];
                  }
               }
               else if(EGComponent(_loc4_).extention is EGLabel)
               {
                  if(_loc3_[1])
                  {
                     EGLabel(EGComponent(_loc4_).extention).title = _loc3_[1];
                  }
                  if(_loc3_[2])
                  {
                     EGLabel(EGComponent(_loc4_).extention).icon = _loc3_[2];
                  }
               }
            }
            _loc2_++;
         }
      }
      
      override protected function updateBounds() : void
      {
         var _loc2_:int = 0;
         var _loc3_:int = 0;
         var _loc4_:EGObject = null;
         var _loc5_:int = 0;
         var _loc6_:int = 0;
         var _loc7_:int = 0;
         var _loc8_:int = 0;
         var _loc9_:int = 0;
         var _loc10_:int = 0;
         var _loc12_:Number = NaN;
         var _loc17_:int = 0;
         var _loc18_:int = 0;
         var _loc19_:int = 0;
         var _loc1_:int = numChildren;
         var _loc11_:Number = 0;
         var _loc13_:int = this.viewWidth;
         var _loc14_:int = this.viewHeight;
         if(this._layout == SINGLE_COLUMN)
         {
            _loc2_ = 0;
            while(_loc2_ < _loc1_)
            {
               _loc4_ = getChildAt(_loc2_);
               if(_loc2_ != 0)
               {
                  _loc6_ = _loc6_ + this._lineGap;
               }
               _loc4_.setXY(0,_loc6_);
               if(this._autoResizeItem1)
               {
                  _loc4_.setSize(_loc13_,_loc4_.height,true);
               }
               else
               {
                  _loc4_.setSize(_loc4_.sourceWidth,_loc4_.height,true);
               }
               _loc6_ = _loc6_ + Math.ceil(_loc4_.height);
               if(_loc4_.width > _loc9_)
               {
                  _loc9_ = _loc4_.width;
               }
               _loc2_++;
            }
            _loc7_ = Math.ceil(_loc9_);
            _loc8_ = _loc6_;
         }
         else if(this._layout == SINGLE_ROW)
         {
            _loc2_ = 0;
            while(_loc2_ < _loc1_)
            {
               _loc4_ = getChildAt(_loc2_);
               if(_loc2_ != 0)
               {
                  _loc5_ = _loc5_ + this._columnGap;
               }
               _loc4_.setXY(_loc5_,0);
               if(this._autoResizeItem1)
               {
                  _loc4_.setSize(_loc4_.width,_loc14_,true);
               }
               else
               {
                  _loc4_.setSize(_loc4_.width,_loc4_.sourceHeight,true);
               }
               _loc5_ = _loc5_ + Math.ceil(_loc4_.width);
               if(_loc4_.height > _loc10_)
               {
                  _loc10_ = _loc4_.height;
               }
               _loc2_++;
            }
            _loc7_ = _loc5_;
            _loc8_ = Math.ceil(_loc10_);
         }
         else if(this._layout == FLOW_HZ)
         {
            _loc3_ = 0;
            if(this._autoResizeItem2 && this._repeatX > 0)
            {
               _loc2_ = 0;
               while(_loc2_ < _loc1_)
               {
                  _loc4_ = getChildAt(_loc2_);
                  _loc11_ = _loc11_ + _loc4_.sourceWidth;
                  _loc3_++;
                  if(_loc3_ == this._repeatX || _loc2_ == _loc1_ - 1)
                  {
                     _loc12_ = (_loc13_ - _loc11_ - (_loc3_ - 1) * this._columnGap) / _loc11_;
                     _loc5_ = 0;
                     _loc3_ = _loc2_ - _loc3_ + 1;
                     while(_loc3_ <= _loc2_)
                     {
                        _loc4_ = getChildAt(_loc3_);
                        _loc4_.setXY(_loc5_,_loc6_);
                        if(_loc3_ < _loc2_)
                        {
                           _loc4_.setSize(_loc4_.sourceWidth + Math.round(_loc4_.sourceWidth * _loc12_),_loc4_.height,true);
                           _loc5_ = _loc5_ + (Math.ceil(_loc4_.width) + this._columnGap);
                        }
                        else
                        {
                           _loc4_.setSize(_loc13_ - _loc5_,_loc4_.height,true);
                        }
                        if(_loc4_.height > _loc10_)
                        {
                           _loc10_ = _loc4_.height;
                        }
                        _loc3_++;
                     }
                     _loc6_ = _loc6_ + (Math.ceil(_loc10_) + this._lineGap);
                     _loc10_ = 0;
                     _loc3_ = 0;
                     _loc11_ = 0;
                  }
                  _loc2_++;
               }
               _loc8_ = _loc6_ + Math.ceil(_loc10_);
               _loc7_ = _loc13_;
            }
            else
            {
               _loc2_ = 0;
               while(_loc2_ < _loc1_)
               {
                  _loc4_ = getChildAt(_loc2_);
                  if(_loc5_ != 0)
                  {
                     _loc5_ = _loc5_ + this._columnGap;
                  }
                  _loc4_.setSize(_loc4_.sourceWidth,_loc4_.height,true);
                  if(this._repeatX != 0 && _loc3_ >= this._repeatX || this._repeatX == 0 && _loc5_ + _loc4_.width > _loc13_ && _loc10_ != 0)
                  {
                     _loc5_ = 0;
                     _loc6_ = _loc6_ + (Math.ceil(_loc10_) + this._lineGap);
                     _loc10_ = 0;
                     _loc3_ = 0;
                  }
                  _loc4_.setXY(_loc5_,_loc6_);
                  _loc5_ = _loc5_ + Math.ceil(_loc4_.width);
                  if(_loc5_ > _loc9_)
                  {
                     _loc9_ = _loc5_;
                  }
                  if(_loc4_.height > _loc10_)
                  {
                     _loc10_ = _loc4_.height;
                  }
                  _loc3_++;
                  _loc2_++;
               }
               _loc8_ = _loc6_ + Math.ceil(_loc10_);
               _loc7_ = Math.ceil(_loc9_);
            }
         }
         else if(this._layout == FLOW_VT)
         {
            _loc3_ = 0;
            if(this._autoResizeItem2 && this._repeatY > 0)
            {
               _loc2_ = 0;
               while(_loc2_ < _loc1_)
               {
                  _loc4_ = getChildAt(_loc2_);
                  _loc11_ = _loc11_ + _loc4_.sourceHeight;
                  _loc3_++;
                  if(_loc3_ == this._repeatY || _loc2_ == _loc1_ - 1)
                  {
                     _loc12_ = (_loc14_ - _loc11_ - (_loc3_ - 1) * this._lineGap) / _loc11_;
                     _loc6_ = 0;
                     _loc3_ = _loc2_ - _loc3_ + 1;
                     while(_loc3_ <= _loc2_)
                     {
                        _loc4_ = getChildAt(_loc3_);
                        _loc4_.setXY(_loc5_,_loc6_);
                        if(_loc3_ < _loc2_)
                        {
                           _loc4_.setSize(_loc4_.width,_loc4_.sourceHeight + Math.round(_loc4_.sourceHeight * _loc12_),true);
                           _loc6_ = _loc6_ + (Math.ceil(_loc4_.height) + this._lineGap);
                        }
                        else
                        {
                           _loc4_.setSize(_loc4_.width,_loc14_ - _loc6_,true);
                        }
                        if(_loc4_.width > _loc9_)
                        {
                           _loc9_ = _loc4_.width;
                        }
                        _loc3_++;
                     }
                     _loc5_ = _loc5_ + (Math.ceil(_loc9_) + this._columnGap);
                     _loc9_ = 0;
                     _loc3_ = 0;
                     _loc11_ = 0;
                  }
                  _loc2_++;
               }
               _loc7_ = _loc5_ + Math.ceil(_loc9_);
               _loc8_ = _loc14_;
            }
            else
            {
               _loc2_ = 0;
               while(_loc2_ < _loc1_)
               {
                  _loc4_ = getChildAt(_loc2_);
                  if(_loc6_ != 0)
                  {
                     _loc6_ = _loc6_ + this._lineGap;
                  }
                  _loc4_.setSize(_loc4_.width,_loc4_.sourceHeight,true);
                  if(this._repeatY != 0 && _loc3_ >= this._repeatY || this._repeatY == 0 && _loc6_ + _loc4_.height > _loc14_ && _loc9_ != 0)
                  {
                     _loc6_ = 0;
                     _loc5_ = _loc5_ + (Math.ceil(_loc9_) + this._columnGap);
                     _loc9_ = 0;
                     _loc3_ = 0;
                  }
                  _loc4_.setXY(_loc5_,_loc6_);
                  _loc6_ = _loc6_ + _loc4_.height;
                  if(_loc6_ > _loc10_)
                  {
                     _loc10_ = _loc6_;
                  }
                  if(_loc4_.width > _loc9_)
                  {
                     _loc9_ = _loc4_.width;
                  }
                  _loc3_++;
                  _loc2_++;
               }
               _loc7_ = _loc5_ + Math.ceil(_loc9_);
               _loc8_ = Math.ceil(_loc10_);
            }
         }
         else
         {
            _loc3_ = 0;
            _loc17_ = 0;
            _loc18_ = 0;
            if(this._autoResizeItem2 && this._repeatY > 0)
            {
               _loc19_ = (_loc14_ - (this._repeatY - 1) * this._lineGap) / this._repeatY;
            }
            if(this._autoResizeItem2 && this._repeatX > 0)
            {
               _loc2_ = 0;
               while(_loc2_ < _loc1_)
               {
                  _loc4_ = getChildAt(_loc2_);
                  _loc11_ = _loc11_ + _loc4_.sourceWidth;
                  _loc3_++;
                  if(_loc3_ == this._repeatX || _loc2_ == _loc1_ - 1)
                  {
                     _loc12_ = (_loc13_ - _loc11_ - (_loc3_ - 1) * this._columnGap) / _loc11_;
                     _loc5_ = 0;
                     _loc3_ = _loc2_ - _loc3_ + 1;
                     while(_loc3_ <= _loc2_)
                     {
                        _loc4_ = getChildAt(_loc3_);
                        _loc4_.setXY(_loc18_ * _loc13_ + _loc5_,_loc6_);
                        if(_loc3_ < _loc2_)
                        {
                           _loc4_.setSize(_loc4_.sourceWidth + Math.round(_loc4_.sourceWidth * _loc12_),this._repeatY > 0?Number(_loc19_):Number(_loc4_.height),true);
                           _loc5_ = _loc5_ + (Math.ceil(_loc4_.width) + this._columnGap);
                        }
                        else
                        {
                           _loc4_.setSize(_loc13_ - _loc5_,this._repeatY > 0?Number(_loc19_):Number(_loc4_.height),true);
                        }
                        if(_loc4_.height > _loc10_)
                        {
                           _loc10_ = _loc4_.height;
                        }
                        _loc3_++;
                     }
                     _loc6_ = _loc6_ + (Math.ceil(_loc10_) + this._lineGap);
                     _loc10_ = 0;
                     _loc3_ = 0;
                     _loc11_ = 0;
                     _loc17_++;
                     if(this._repeatY != 0 && _loc17_ >= this._repeatY || this._repeatY == 0 && _loc6_ + _loc4_.height > _loc14_)
                     {
                        _loc18_++;
                        _loc6_ = 0;
                        _loc17_ = 0;
                     }
                  }
                  _loc2_++;
               }
            }
            else
            {
               _loc2_ = 0;
               while(_loc2_ < _loc1_)
               {
                  _loc4_ = getChildAt(_loc2_);
                  if(_loc3_ != 0)
                  {
                     _loc5_ = _loc5_ + this._columnGap;
                  }
                  _loc4_.setSize(_loc4_.sourceWidth,(this._autoResizeItem2 && this._repeatY) > 0?Number(_loc19_):Number(_loc4_.sourceHeight),true);
                  if(this._repeatX != 0 && _loc3_ >= this._repeatX || this._repeatX == 0 && _loc5_ + _loc4_.width > _loc13_ && _loc10_ != 0)
                  {
                     _loc5_ = 0;
                     _loc6_ = _loc6_ + (Math.ceil(_loc10_) + this._lineGap);
                     _loc10_ = 0;
                     _loc3_ = 0;
                     _loc17_++;
                     if(this._repeatY != 0 && _loc17_ >= this._repeatY || this._repeatY == 0 && _loc6_ + _loc4_.height > _loc14_ && _loc9_ != 0)
                     {
                        _loc18_++;
                        _loc6_ = 0;
                        _loc17_ = 0;
                     }
                  }
                  _loc4_.setXY(_loc18_ * _loc13_ + _loc5_,_loc6_);
                  _loc5_ = _loc5_ + Math.ceil(_loc4_.width);
                  if(_loc5_ > _loc9_)
                  {
                     _loc9_ = _loc5_;
                  }
                  if(_loc4_.height > _loc10_)
                  {
                     _loc10_ = _loc4_.height;
                  }
                  _loc3_++;
                  _loc2_++;
               }
            }
            _loc8_ = _loc18_ > 0?int(_loc14_):int(_loc6_ + Math.ceil(_loc10_));
            _loc7_ = (_loc18_ + 1) * _loc13_;
         }
         setBounds(0,0,_loc7_,_loc8_);
         var _loc15_:Number = alignOffset.x;
         var _loc16_:Number = alignOffset.y;
         alignOffset.x = 0;
         alignOffset.y = 0;
         if(_loc8_ < _loc14_)
         {
            if(this._verticalAlign == "middle")
            {
               alignOffset.y = int((_loc14_ - _loc8_) / 2);
            }
            else if(this._verticalAlign == "bottom")
            {
               alignOffset.y = _loc14_ - _loc8_;
            }
         }
         if(_loc7_ < _loc13_)
         {
            if(this._align == "center")
            {
               alignOffset.x = int((_loc13_ - _loc7_) / 2);
            }
            else if(this._align == "right")
            {
               alignOffset.x = _loc13_ - _loc7_;
            }
         }
         if(alignOffset.x != _loc15_ || alignOffset.y != _loc16_)
         {
            updateOverflow();
         }
      }
      
      override public function create() : void
      {
         super.create();
         if(editMode == 2)
         {
            _displayObject.setDashedRect(true,"List");
         }
      }
      
      override public function fromXML_beforeAdd(param1:XML) : void
      {
         var _loc2_:String = null;
         var _loc4_:Array = null;
         var _loc5_:XML = null;
         var _loc6_:String = null;
         super.fromXML_beforeAdd(param1);
         _loc2_ = param1.@layout;
         if(_loc2_)
         {
            this._layout = _loc2_;
         }
         else
         {
            this._layout = SINGLE_COLUMN;
         }
         _loc2_ = param1.@selectionMode;
         if(_loc2_)
         {
            this._selectionMode = _loc2_;
         }
         else
         {
            this._selectionMode = "single";
         }
         _loc2_ = param1.@margin;
         if(_loc2_)
         {
            _margin.parse(_loc2_);
         }
         _loc2_ = param1.@clipSoftness;
         if(_loc2_)
         {
            _loc4_ = _loc2_.split(",");
            _clipSoftness.x = int(_loc4_[0]);
            _clipSoftness.y = int(_loc4_[1]);
         }
         _loc2_ = param1.@overflow;
         if(_loc2_)
         {
            _overflow = _loc2_;
         }
         else
         {
            _overflow = EOverflowConst.VISIBLE;
         }
         _loc2_ = param1.@scroll;
         if(_loc2_)
         {
            _scroll = _loc2_;
         }
         else
         {
            _scroll = EScrollConst.VERTICAL;
         }
         _scrollBarFlags = parseInt(param1.@scrollBarFlags);
         _loc2_ = param1.@scrollBar;
         if(_loc2_)
         {
            _scrollBarDisplay = _loc2_;
         }
         else
         {
            _scrollBarDisplay = EScrollBarDisplayConst.DEFAULT;
         }
         _loc2_ = param1.@scrollBarMargin;
         if(_loc2_)
         {
            _scrollBarMargin.parse(_loc2_);
         }
         _loc2_ = param1.@scrollBarRes;
         if(_loc2_)
         {
            _loc4_ = _loc2_.split(",");
            _vtScrollBarRes = _loc4_[0];
            _hzScrollBarRes = _loc4_[1];
         }
         _loc2_ = param1.@ptrRes;
         if(_loc2_)
         {
            _loc4_ = _loc2_.split(",");
            _headerRes = _loc4_[0];
            _footerRes = _loc4_[1];
         }
         _loc2_ = param1.@lineGap;
         if(_loc2_)
         {
            this._lineGap = parseInt(_loc2_);
         }
         else
         {
            this._lineGap = 0;
         }
         _loc2_ = param1.@colGap;
         if(_loc2_)
         {
            this._columnGap = parseInt(_loc2_);
         }
         else
         {
            this._columnGap = 0;
         }
         this._repeatX = this._repeatY = 0;
         _loc2_ = param1.@lineItemCount;
         if(_loc2_)
         {
            if(this._layout == FLOW_HZ || this._layout == PAGINATION)
            {
               this._repeatX = parseInt(_loc2_);
            }
            else if(this._layout == FLOW_VT)
            {
               this._repeatY = parseInt(_loc2_);
            }
         }
         _loc2_ = param1.@lineItemCount2;
         if(_loc2_)
         {
            this._repeatY = parseInt(_loc2_);
         }
         _loc2_ = param1.@defaultItem;
         if(_loc2_)
         {
            this._defaultItem = _loc2_;
         }
         _loc2_ = param1.@autoItemSize;
         if(this._layout == SINGLE_ROW || this._layout == SINGLE_COLUMN)
         {
            this._autoResizeItem1 = _loc2_ != "false";
         }
         else
         {
            this._autoResizeItem2 = _loc2_ == "true";
         }
         _loc2_ = param1.@align;
         if(_loc2_)
         {
            this._align = _loc2_;
         }
         else
         {
            this._align = "left";
         }
         _loc2_ = param1.@vAlign;
         if(_loc2_)
         {
            this._verticalAlign = _loc2_;
         }
         else
         {
            this._verticalAlign = "top";
         }
         updateOverflow();
         _loc2_ = param1.@renderOrder;
         if(_loc2_)
         {
            _childrenRenderOrder = _loc2_;
            if(_childrenRenderOrder == "arch")
            {
               _loc2_ = param1.@apex;
               if(_loc2_)
               {
                  _apexIndex = parseInt(_loc2_);
               }
            }
         }
         var _loc3_:XMLList = param1.item;
         _loc4_ = [];
         for each(_loc5_ in _loc3_)
         {
            _loc6_ = String(_loc5_.@url);
            if(!_loc6_)
            {
               _loc6_ = this._defaultItem;
            }
            _loc4_.push([_loc6_,String(_loc5_.@title),String(_loc5_.@icon),String(_loc5_.@name)]);
         }
         this.items = _loc4_;
      }
      
      override public function fromXML_afterAdd(param1:XML) : void
      {
         super.fromXML_afterAdd(param1);
         var _loc2_:String = param1.@selectionController;
         if(_loc2_)
         {
            this._selectionController = parent.getController(_loc2_);
         }
         else
         {
            this._selectionController = null;
         }
      }
      
      override public function toXML() : XML
      {
         var _loc2_:Array = null;
         var _loc3_:XML = null;
         var _loc1_:XML = super.toXML();
         if(this._layout != SINGLE_COLUMN)
         {
            _loc1_.@layout = this._layout;
         }
         if(this._selectionMode != "single")
         {
            _loc1_.@selectionMode = this._selectionMode;
         }
         if(_overflow != EOverflowConst.VISIBLE)
         {
            _loc1_.@overflow = _overflow;
         }
         if(_scroll != EScrollConst.VERTICAL)
         {
            _loc1_.@scroll = _scroll;
         }
         if(_overflow == EOverflowConst.SCROLL)
         {
            if(_scrollBarFlags)
            {
               _loc1_.@scrollBarFlags = _scrollBarFlags;
            }
            if(_scrollBarDisplay != EScrollBarDisplayConst.DEFAULT)
            {
               _loc1_.@scrollBar = _scrollBarDisplay;
            }
         }
         if(!_margin.empty)
         {
            _loc1_.@margin = _margin;
         }
         if(!_scrollBarMargin.empty)
         {
            _loc1_.@scrollBarMargin = _scrollBarMargin.toString();
         }
         if(_vtScrollBarRes || _hzScrollBarRes)
         {
            _loc1_.@scrollBarRes = (!!_vtScrollBarRes?_vtScrollBarRes:"") + "," + (!!_hzScrollBarRes?_hzScrollBarRes:"");
         }
         if(_headerRes || _footerRes)
         {
            _loc1_.@ptrRes = (!!_headerRes?_headerRes:"") + "," + (!!_footerRes?_footerRes:"");
         }
         if(_clipSoftness.x != 0 || _clipSoftness.y != 0)
         {
            _loc1_.@clipSoftness = _clipSoftness.x + "," + _clipSoftness.y;
         }
         if(this._lineGap != 0)
         {
            _loc1_.@lineGap = this._lineGap;
         }
         if(this._columnGap != 0)
         {
            _loc1_.@colGap = this._columnGap;
         }
         if(this._layout == FLOW_HZ)
         {
            if(this._repeatX != 0)
            {
               _loc1_.@lineItemCount = this._repeatX;
            }
         }
         else if(this._layout == FLOW_VT)
         {
            if(this._repeatY != 0)
            {
               _loc1_.@lineItemCount = this._repeatY;
            }
         }
         else if(this._layout == PAGINATION)
         {
            if(this._repeatX != 0)
            {
               _loc1_.@lineItemCount = this._repeatX;
            }
            if(this._repeatY != 0)
            {
               _loc1_.@lineItemCount2 = this._repeatY;
            }
         }
         if(this._defaultItem)
         {
            _loc1_.@defaultItem = this._defaultItem;
         }
         if(this._layout == SINGLE_ROW || this._layout == SINGLE_COLUMN)
         {
            if(!this._autoResizeItem1)
            {
               _loc1_.@autoItemSize = false;
            }
         }
         else if(this._autoResizeItem2)
         {
            _loc1_.@autoItemSize = true;
         }
         if(this._align != "left")
         {
            _loc1_.@align = this._align;
         }
         if(this._verticalAlign != "top")
         {
            _loc1_.@vAlign = this._verticalAlign;
         }
         if(_childrenRenderOrder != "ascent")
         {
            _loc1_.@renderOrder = _childrenRenderOrder;
            if(_childrenRenderOrder == "arch" && _apexIndex != 0)
            {
               _loc1_.@apex = _apexIndex;
            }
         }
         if(this._selectionController && this._selectionController.parent)
         {
            _loc1_.@selectionController = this._selectionController.name;
         }
         if(this._items.length)
         {
            for each(_loc2_ in this._items)
            {
               _loc3_ = <item/>;
               if(_loc2_[0] && _loc2_[0] != this._defaultItem)
               {
                  _loc3_.@url = _loc2_[0];
               }
               if(_loc2_[1])
               {
                  _loc3_.@title = _loc2_[1];
               }
               if(_loc2_[2])
               {
                  _loc3_.@icon = _loc2_[2];
               }
               if(_loc2_[3])
               {
                  _loc3_.@name = _loc2_[3];
               }
               _loc1_.appendChild(_loc3_);
            }
         }
         return _loc1_;
      }
   }
}
